<template>
	<view>
		<view class="cu-form-group" @tap="onCityClick">
			<view  class="zh-picker" :style="{'justify-content':justifyContent}" >
				<view v-if="iconClass||label" class="title" :style="{'width':labelWidth,'text-align':labelAlign}">
					<text v-if="required" class="text-red " style="padding-right: 4rpx;" :style="{'font-size':fontSize}">*</text>
					<text v-if="iconClass" :class="iconClass?iconClass:''" style="padding-right: 6rpx;" :style="{'font-size':fontSize}"></text>
					<text v-if="label" :style="{'font-size':fontSize}">{{ label }}</text>
				</view>
				<view :style="{'font-size':fontSize,'text-align':inputAlign}" :class="addressValue?'':'input-placeholder-class'">{{addressValue?addressValue:placeholder}}</view>
			</view>
			<text style="padding-left: 20rpx;" :style="{'font-size':fontSize}" :class="rightIconClass?rightIconClass:'text-gray'" class="cuIcon-right"></text>
			
		</view>
		<select-address :ref='addressRef' :value="value" @confirm="onConfirm" ></select-address>
	</view>
</template>

<script>
	export default {
		props:{
			iconClass: {
				type:[Array, String],
				default(){
					return ''
				}
			},
			rightIconClass: {
				type:[Array, String],
				default(){
					return ''
				}
			},
			required: Boolean,
			label:String,
			fontSize: {
				type: String,
				default: '28rpx'
			},
			// 左边标题的宽度单位rpx
			labelWidth: {
				type: [Number, String],
				default: 'auto'
			},
			// 标题对齐方式，left|center|right
			labelAlign: {
				type: String,
				default: 'right'
			},
			// 输入框对齐方式
			inputAlign: {
				type: String,
				default: 'left'
			},
			justifyContent:{
				type:String,
				default:"flex-start"
			},
			disabled: {
				type: Boolean,
				default: false
			},
			placeholder:{
				type:String,
				default:"==请选择=="
			},
			value:{//默认值
				type:[String,Array,Number],
				default:""
			},
			current:{//是否默认显示当前时间，如果是，传的默认值将失效
				type:Boolean,
				default:false
			},
			themeColor:{//确认按钮主题颜色
				type:String,
				default:"#0081ff"
			},
			addressRef:{
				type:String,
				default:"addressSelect"
			},
		},
		data() {
			return {
				addressValue:''
			}
		},
		methods: {
			onCityClick(){
				this.$refs.addressSelect.show();
			},
			onConfirm(data){
				console.log(data)
				this.$emit('addressChange', data);
				if(data){
					let address=data.province.label
					if(data.city.label){
						address = address+"-"+data.city.label
					}
					if(data.county.label){
						address = address+"-"+data.county.label
					}
					if(data.town.label){
						address = address+"-"+data.town.label
					}
					this.addressValue = address
				}else{
					this.addressValue = ''
				}
			}
		}
	}
</script>

<style lang="scss">
	.input-placeholder-class {
		color: $uni-text-color-placeholder;
	}
</style>
